Skip to content

fix: Add integration tests for Nostr relay sync#6

Open
Xanoutas wants to merge 1 commit intosingularityjason:mainfrom
Xanoutas:fix/issue-5-auto
Open

fix: Add integration tests for Nostr relay sync#6
Xanoutas wants to merge 1 commit intosingularityjason:mainfrom
Xanoutas:fix/issue-5-auto

Conversation

@Xanoutas
Copy link

@Xanoutas Xanoutas commented Mar 7, 2026

Fix for #5: Add integration tests for Nostr relay sync

# tests/test_nostr_relay_sync.py
import pytest
from lightning_memory.nostr import NostrRelay, NostrEvent
from lightning_memory.sync import NostrSync

@pytest.fixture
def mock_relay():
    class MockRelay(NostrRelay):
        def __init__(self):
            self.published_events = []

        def publish(self, event):
            self.published_events.append(event)

        def subscribe(self, filter):
            # For simplicity, return all published events
            return self.published_events

    return MockRelay()

def test_publish_event(mock_relay):
    nostr_sync = NostrSync(relay=mock_relay)
    event = NostrEvent(content="Test event", kind=1)
    nostr_sync.publish(event)
    assert len(mock_relay.published_events) == 1
    assert mock_relay.published_events[0] == event

def test_bidirectional_sync(mock_relay):
    nostr_sync = NostrSync(relay=mock_relay)
    event1 = NostrEvent(content="First event", kind=1)
    event2 = NostrEvent(content="Second event", kind=1)
    nostr_sync.publish(event1)
    nostr_sync.publish(event2)
    subscribed_events = nostr_sync.subscribe()
    assert len(subscribed_events) == 2
    assert subscribed_events[0] == event1
    assert subscribed_events[1] == event2

Explanation:

  1. Mock Relay Implementation: A MockRelay class is created to simulate a Nostr relay. It stores published events in a list and returns them when subscribed to.
  2. Test Publish Event: This test checks if an event is correctly published to the mock relay. It asserts that the event is added to the published_events list.
  3. Test Bidirectional Sync: This test checks both publishing and subscribing. It publishes two events and then subscribes to verify that both events are returned.

These tests ensure that the Nostr relay sync functionality works as expected using a mock relay, which is suitable for integration testing without relying on an actual Nostr relay server.


Closes #5

Auto-generated fix | deepseek-coder:33b (RTX 5070)
EVM: 0x22FD4d24771358fD18a3964456CD5F9d7b6E8f9f | SOL: C4PcQjqDW4a5Pvhx5ZFPvAodkGiVG49q8dMvpskqSvuH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add integration tests for Nostr relay sync

1 participant